package com.diyizu.factory;

import com.diyizu.controller.ILoginController;
import com.diyizu.controller.IRegController;
import com.diyizu.controller.IStudentInfoController;
import com.diyizu.controller.StatisticalReportController;
import com.diyizu.controller.impl.BayExcle;
import com.diyizu.controller.impl.Extensions;
import com.diyizu.controller.impl.ToExcle;
import com.diyizu.dao.IStudentInfoDao;
import com.diyizu.dao.IUserDao;
import com.diyizu.dao.impl.ReadLogDao;
import com.diyizu.dao.impl.StudentInfoDaoImpl;
import com.diyizu.service.ILoginService;
import com.diyizu.service.IRegService;
import com.diyizu.service.IStudentInfoService;
import com.diyizu.service.impl.StudentInfoServiceImpl;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.Properties;

/**
 * 工厂类
 */
public class Factory {
    private static Properties properties = new Properties();
    private  static InputStream is = ClassLoader.getSystemResourceAsStream("bean.properties");

    public static IStudentInfoController getStudentInfoController(){
        Object o =null;
        try {
            properties.load(is);
            Class studentInfoControllerImpl = Class.forName(properties.getProperty("StudentInfoControllerImpl"));
            Constructor constructor = studentInfoControllerImpl.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (IStudentInfoController) o;
    }

    public static IStudentInfoService getStudentInfoService(){
        Object o =null;
        try {
            properties.load(is);
            Class studentInfoServiceImpl = Class.forName(properties.getProperty("StudentInfoServiceImpl"));
            Constructor constructor = studentInfoServiceImpl.getConstructor();
             o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (IStudentInfoService) o;
    }

    public static IStudentInfoDao getStudentInfoDao(){
        Object o =null;
        try {
            properties.load(is);
            Class studentInfoDaoImpl = Class.forName(properties.getProperty("StudentInfoDaoImpl"));
            Constructor constructor = studentInfoDaoImpl.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (IStudentInfoDao) o;
    }

    public static ILoginController getILoginController(){
        Object o =null;
        try {
            properties.load(is);
            Class loginControllerImpl = Class.forName(properties.getProperty("ILoginControllerImpl"));
            Constructor constructor = loginControllerImpl.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (ILoginController) o;
    }

    public static IRegController getIRegController(){
        Object o =null;
        try {
            properties.load(is);
            Class regControllerImpl = Class.forName(properties.getProperty("IRegControllerImpl"));
            Constructor constructor = regControllerImpl.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (IRegController) o;
    }
    public static ILoginService getILoginService(){
        Object o =null;
        try {
            properties.load(is);
            Class loginServiceImpl = Class.forName(properties.getProperty("ILoginServiceImpl"));
            Constructor constructor = loginServiceImpl.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (ILoginService) o;
    }
    public static IRegService getIRegService(){
        Object o =null;
        try {
            properties.load(is);
            Class regServiceImpl = Class.forName(properties.getProperty("IRegServiceImpl"));
            Constructor constructor = regServiceImpl.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (IRegService) o;
    }
    public static IUserDao getIUserDaoImpl(){
        Object o =null;
        try {
            properties.load(is);
            Class userDaoImpl = Class.forName(properties.getProperty("IUserDaoImpl"));
            Constructor constructor = userDaoImpl.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (IUserDao) o;
    }
    public static Extensions getExtensions(){
        Object o =null;
        try {
            properties.load(is);
            Class extensions = Class.forName(properties.getProperty("Extensions"));
            Constructor constructor = extensions.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (Extensions) o;
    }
    public static StatisticalReportController getStatisticalReportController(){
        Object o =null;
        try {
            properties.load(is);
            Class statisticalReportController = Class.forName(properties.getProperty("StatisticalReportController"));
            Constructor constructor = statisticalReportController.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (StatisticalReportController) o;
    }
    public static ToExcle getToExcle(){
        Object o =null;
        try {
            properties.load(is);
            Class toExcle = Class.forName(properties.getProperty("ToExcle"));
            Constructor constructor = toExcle.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (ToExcle) o;
    }
    public static BayExcle getBayExcle(){
        Object o =null;
        try {
            properties.load(is);
            Class bayExcle = Class.forName(properties.getProperty("BayExcle"));
            Constructor constructor = bayExcle.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (BayExcle) o;
    }
    public static ReadLogDao getReadLogDao(){
        Object o =null;
        try {
            properties.load(is);
            Class readLogDao = Class.forName(properties.getProperty("ReadLogDao"));
            Constructor constructor = readLogDao.getConstructor();
            o = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (ReadLogDao) o;
    }
}